<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller_Admin_Base extends Controller
{
    protected $title  = 'Recensee.Com';
	protected $layout = 'admin/layout_tpl';
    protected $need_auth = true;
    protected $message = null;
    
    protected function is_need_auth()
    {
        return $this->need_auth;
    }
    
    protected function add_message($message)
    {
        $this->message = $message;   
    }
    
    public function before()
    {
        $shop_id = $this->request->param('shop_id');
        ORM::factory('shop', $shop_id)->set_as_current();
        
        if (!Model_Auth::instance()->logged_in(Model_User_Shop::ROLE_ADMINISTRATOR) && $this->is_need_auth()) {
            Request::current()->redirect(Helper_Admin::get_url().'/login');    
        }
    }
	
	public function print_template($title, $content)
	{
        $this->layout = new View($this->layout);

		$this->layout->title       = $title.' - '.$this->title;
		$this->layout->content     = $content;
        $this->layout->message     = $this->message;
		
		$this->response->body($this->layout);
	}

}
